USE $(StarterKitDb)
GO

PRINT 'Checking convertation'
GO
IF OBJECT_ID('tempdb..#Convertation') IS NOT NULL 
BEGIN
	DECLARE 
		@CurVersion nvarchar(10), @NewVersion nvarchar(10)

	SET @CurVersion = (SELECT OptionValue FROM dbo.SystemOption WHERE OptionName = 'Database_version')
	SET @NewVersion = (SELECT Version FROM #Convertation)

	PRINT 'Current version '+@CurVersion+' New version '+@NewVersion

	if(@NewVersion > @CurVersion)
	BEGIN
		PRINT 'Convert database.'
/*

		IF (@CurVersion='1.0.0.0')
			EXEC [#convert1.0.0.0_1.0.0.1] @Version=@CurVersion OUTPUT
*/
		UPDATE dbo.SystemOption
			SET OptionValue=@CurVersion
		WHERE OptionName = 'Database_version'
	END
	ELSE BEGIN
		PRINT 'There is no need to convert database'
	END
END
GO